<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>用户列表</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<!-- /Head -->
<!-- Body -->
<body>
<div class="page-body">
    <div class="panel panel-primary shiny">
        <div class="panel-heading bg-blue">
            用户列表
        </div>
        <div class="widget-body grid-table">
            <div class="toolbar">
                <div class="fl-left">
                    <button data-menu-id="050501" data-click="add('account/userAdd.html','userList')" class="btn btn-blue shiny">新增用户</button>
                    <button data-menu-id="050502" data-click="del('userList','user/delUser', false)" class="btn btn-danger shiny">刪除用户</button>
                </div>
                <div class="toolbar-right">
                    <div class="fl-right">
                        <div class="btn-group" role="group">
                            <button data-click="toggleFilter()" class="btn btn-default text-center">
                                <i class="fa fa-filter fa-fw"></i>
                            </button>
                            <button data-click="refresh('userList')" class="btn btn-default">
                                <i class="fa fa-refresh fa-fw"></i>
                            </button>
                            <button data-click="download('userList')" class="btn btn-default">
                                <i class="fa fa-download fa-fw"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div id="userList"></div>
            <form class="filter search-content form-horizontal" data-width="650" role="form">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label">用户名：</label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <input name="username" type="text" class="form-control spinner" placeholder="用户名称">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label">所属组织：</label>
                        <div class="col-xs-8">
                            <select name="orgId" id="orgId" class="form-control spinner" data-url="org/listOrg" data-value-field="id" data-text-field="orgName" data-value="-1">
                                <option value="-1">全部</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label">所属角色：</label>
                        <div class="col-xs-8">
                            <select name="roleId" id="roleId" class="form-control spinner">
                                <option value="-1">全部</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <button type="button" data-click="hideFilter()" class="btn btn-default pull-right">取消</button>
                    <button type="button" data-click="submitFilter('userList')" class="btn btn-blue pull-right">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<!--  /Body -->
</html>
<script>
    $(function () {
        $("#userList").gridTable({
            url: "user/pageUser",
            columns: [
                {title: "用户编号", field: "id"},
                {title: "用户名", field: "username"},
                {title: "用户姓名", field: "realName"},
                {title: "组织名称", field: "orgName"},
                {title: "角色名称", field: "roleName"},
                {title: "用户状态", field: "userStatusStr"},
                {title: "创建时间", field: "createTime"},
                {title: "更新时间", field: "updateTime"}
            ],
            idField: "id",
            infoUrl: "account/userInfo.html",
            editUrl: "account/userEdit.html",
            delUrl: "user/delUser"
        });
        var $roleId = $("#roleId");
        $("#orgId").on("change", function () {
            // 先锁住下拉框，防止加载数据时用户更改
            $(this).attr("disabled", true);
            var that = this;
            var value = $(that).val();
            $.doAjax("role/listRole", {orgId: value}, function (roleList) {
                $roleId.empty().attr("disabled", false).append($("<option value='-1'>全部</option>"));
                $roleId.val("-1");
                roleList.forEach(function (role) {
                    var option = $("<option></option>");
                    option.attr("value", role.id);
                    option.text(role.roleName);
                    $("#roleId").append(option);
                });
                $(that).attr("disabled", false);
            });
        });
    });

</script>
